<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:a4j="http://richfaces.org/a4j"
      xmlns:rich="http://richfaces.org/rich"
      xmlns:f="http://java.sun.com/jsf/core">

    <!--
    
    Copyright 2007-2012 Audrius Valunas

    This file is part of LibreACS.

    LibreACS is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    LibreACS is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with LibreACS.  If not, see <http://www.gnu.org/licenses/>.

    -->

    <ui:composition template="mt.xhtml">
        <ui:define name="title">Configuration script management</ui:define>
        <ui:define name="body">
            <h4><h:outputText value="#{Script.new ? 'New script' : Script.name}" /></h4>
            <p>Here you can edit configuration scripts. Syntax is javascript. On Inform request the script named 'Default' is run. More ...</p>
            <h:form id="scriptform">
                <h:inputHidden value="#{Script.name}"/>
                <h:panelGrid columns="1">
                    <h:outputText value="Name:" rendered="#{Script.new}"/>
                    <h:inputText value="#{Script.name}" rendered="#{Script.new}"/>
                    <h:outputText value="Description:" />
                    <h:inputText value="#{Script.description}"/>
                    <h:outputText value="Script:" />
                    <h:inputTextarea  rows="20" cols="100" value="#{Script.text}"/>
                </h:panelGrid>
                <div style="display: #{Script.new ? 'none' : 'block'}">
                    <h:commandButton class="rich-button" value="Save" action="#{Script.Save}" />
                    <h:commandButton class="rich-button" value="Delete" action="#{Script.Delete}" onclick="if (!confirm('Are you sure?')) { return false; }"/>
                </div>
                <div style="display: #{Script.new ? 'block' : 'none'}">
                    <h:commandButton class="rich-button" type="submit" value="Create" action="#{Script.Create}" />
                </div>

            </h:form>
        </ui:define>
        <ui:define name="lmenu">
            <a4j:form>
                <rich:panelBar width="100%">
                    <rich:panelBarItem   id="scriptList" label="Configuration scripts">
                        <table border="0" cellpadding="0" cellspacing="1">
                            <tbody>
                                <tr class="unactive" onmouseover="this.className='active';" onmouseout="this.className='unactive'">
                                    <td class="ico"><h:graphicImage value="/images/icon_script.gif" width="16" height="16" alt="" border="0" /></td>
                                    <td class="text" width="100%">
                                        <h:commandLink style="display:block;height:20px" value="Create ...">
                                        </h:commandLink>
                                    </td>
                                </tr>
                                <a4j:repeat var="script" value="#{Script.all}">
                                    <tr class="unactive" onmouseover="this.className='active';" onmouseout="this.className='unactive'">
                                        <td class="ico"><h:graphicImage value="/images/icon_script.gif" width="16" height="16" alt="" border="0" /></td>
                                        <td class="text" width="100%">
                                            <h:commandLink style="display:block;height:20px" value="#{script.name}">
                                                <a4j:actionparam name="scriptname" value="#{script.name}"/>
                                            </h:commandLink>
                                        </td>
                                    </tr>
                                </a4j:repeat>
                            </tbody>
                        </table>
                    </rich:panelBarItem>
                </rich:panelBar>
            </a4j:form>
        </ui:define>

    </ui:composition>
</html>